package com.mall.admin.controller;

import cn.hutool.core.convert.Convert;
import com.mall.admin.service.UmsRoleService;
import com.mall.commons.utils.R;
import com.mall.domain.UmsRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
public class UmsRoleController {
    @Autowired
    private UmsRoleService umsRoleService;
    @PostMapping("/allocMenu")
    public R allocMenu(Integer [] menuIds,Integer roleId){
        return umsRoleService.allocMenu(menuIds, roleId);
    }
    @PostMapping("/allocResource")
    public R allocResource(Integer []  resourceIds,Integer roleId){
        return umsRoleService.allocResource(resourceIds, roleId);
    }
   @PostMapping("/create")
    public R create(@RequestBody UmsRole role ){
       return umsRoleService.create(role);
   }
   @PostMapping("/delete")
    public R delete(Integer[] ids){
      return umsRoleService.delete(ids);
   }
   @GetMapping("list")
    public R list(String keyword,Integer pageNum,Integer pageSize){
      return umsRoleService.list(keyword,pageNum,pageSize);
   }
  @GetMapping("listAll")
    public R listAll(){
        return umsRoleService.listAll();
  }
  @GetMapping("listMenu/{roleId}")
    public R listMenu(@PathVariable Integer roleId){
        return umsRoleService.listMenu(roleId);
  }
  @GetMapping("/listResource/{roleId}")
    public R listResource(@PathVariable Integer roleId){
        return umsRoleService.listResource(roleId);
  }
 @PostMapping("/update/{id}")
    public R update(@PathVariable Integer id,@RequestBody UmsRole role){
        role.setId(Convert.toLong(id));
        return umsRoleService.update(role);
 }
 @PostMapping("/updateStatus/{id}")
    public R updateStatus(Integer status, @PathVariable Integer id){
        return umsRoleService.updateStatus(status, id);

 }
}
